//    Copyright (C) Kherty.  All rights reserved.
using System;

namespace OpenLS.Chart.UI
{
    class ValueAxisProjector
    {
        public ValueAxisProjector(double valueMinimum, double valueMaximum, double visualMinimum, double visualMaximum, AxisOrientation orientation)
        {
            VisualMinimum = visualMinimum;
            VisualMaximum = visualMaximum;
            ValueMaximum = valueMaximum;
            ValueMinimum = valueMinimum;
            Orientation = orientation;
            ValueDelta = ValueMaximum - ValueMinimum;
            visualDelta = VisualMaximum - VisualMinimum;
        }

        public double GetValue(double value)
        {
            if (ValueMaximum == ValueMinimum)
                return VisualMinimum;
            switch (Orientation)
            {
                case AxisOrientation.MinimumToMaximum:
                    return VisualMinimum + visualDelta*(value - ValueMinimum)/(ValueDelta);
                    case AxisOrientation.MaximumToMinimum:
                    return VisualMinimum + visualDelta*(ValueMaximum - value)/(ValueDelta);
                    default:
                    throw new NotSupportedException();
            }
        }

        private readonly double ValueDelta;
        private readonly double visualDelta;
        private readonly double VisualMinimum;
        private readonly double VisualMaximum;
        private readonly double ValueMinimum;
        private readonly double ValueMaximum;
        private readonly AxisOrientation Orientation;
    }
}
